//
//  KLBaseTabbarController.m
//  BIBILILI
//
//  Created by WTFKL on 2017/9/18.
//  Copyright © 2017年 WTF. All rights reserved.
//

#import "KLBaseTabbarController.h"
#import "KLBaseNavigationController.h"
#import "KLHomeViewController.h"
#import "KLOtherViewController.h"
#import "KLDynamicViewController.h"
#import "KLMineViewController.h"
@interface KLBaseTabbarController ()

@end

@implementation KLBaseTabbarController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tabBar.barTintColor = [UIColor whiteColor];
    
    [self setUpChildViewController:[[KLHomeViewController alloc] init] title:@"首页" imageName:@"home_home_tab" selectImageName:@"home_home_tab_s"];
    [self setUpChildViewController:[[KLOtherViewController alloc] init] title:@"分区" imageName:@"home_category_tab" selectImageName:@"home_category_tab_s"];
    [self setUpChildViewController:[[KLDynamicViewController alloc] init] title:@"动态" imageName:@"home_pegasus_attention_tab" selectImageName:@"home_pegasus_attention_tab_s"];
    [self setUpChildViewController:[[KLMineViewController alloc] init] title:@"我的" imageName:@"home_mine_tab" selectImageName:@"home_mine_tab_s"];

}


-(void)setUpChildViewController:(UIViewController *)vc title:(NSString *)title imageName:(NSString *)imageName selectImageName:(NSString *)selectImageName{
    vc.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:imageName];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectImageName];
    vc.tabBarItem.title = nil;
    [vc.tabBarItem setImageInsets:UIEdgeInsetsMake(5, 0, -5, 0)];
    [self addChildViewController:[[KLBaseNavigationController alloc] initWithRootViewController:vc]];
}

-(void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];
    if (__KLSTATUSBARHEIGHT__ > 20) {
        
        CGRect frame = self.tabBar.frame;
        frame.size.height = 49;
        frame.origin.y = self.view.frame.size.height - frame.size.height;
        self.tabBar.frame = frame;
        for (UITabBarItem *item in self.tabBar.items) {
            item.imageInsets = UIEdgeInsetsMake(20,0, -20, 0);
            [item setTitlePositionAdjustment:UIOffsetMake(0, 32)];
        }
    }
}

@end
